# Maintainer: Dominika Liberda <ja@sdomi.pl>
# Contributor: Dominika Liberda <ja@sdomi.pl>
pkgname=terra
pkgver=1.0.0
pkgrel=0
pkgdesc="Low-level system programming language embedded in and meta-programmed by Lua."
url="https://terralang.org/"
arch="x86_64"
license="MIT"
makedepends="
	clang-dev
	clang-static
	cmake
	libedit-dev
	libexecinfo-dev
	libffi-dev
	libxml2-dev
	llvm-dev
	llvm-static
	luajit-dev
	ncurses-dev
	openmp-dev
	samurai
	zlib-dev
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/terralang/terra/archive/refs/tags/release-$pkgver.tar.gz
	backtrace_link.patch
	system-lua.patch
	version.patch
	"
subpackages="$pkgname-dev"
builddir="$srcdir/$pkgname-release-$pkgver"

prepare() {
	default_prepare

	# checks if puts() returns 10
	rm tests/string.t
	# includes immintrin.h without include path
	rm tests/expvec.t
	# ?
	rm tests/option_e.t
	rm tests/dynlib.t
}

build() {
	cmake -G Ninja -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DTERRA_STATIC_LINK_LUAJIT=OFF \
		-DTERRA_VERSION="$pkgver"
	cmake --build build
}

check() {
	cd tests
	INCLUDE_PATH="$(pkg-config --variable=includedir luajit)" \
	../build/bin/terra run
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	rm -rf "$pkgdir"/usr/share/terra/tests
}

sha512sums="
cac668637319d56c9563e3a4601a02da4e7924d38b7d7f32a28cdaf61092913ec87e296db25cfe5543b8fd572d1d72e719101194b5e3b681c8b50a28b59648bc  terra-1.0.0.tar.gz
9f7a860a16bc55bed8330395e0de4a8a04066bacef28493e3b15013d64c62a679e474f00f6269767f7d07951d32dd896e50718bf4209570102872cb871e120a5  backtrace_link.patch
aa237ec0e175b2c2d1d996198d443dcb677ca8f33fc0fc980fc31d8a07ca83ff083f7470cf800fd8cbf21f07d79dd099b61740d769931a858dd6bdbdc0247df9  system-lua.patch
d2beea5e219951c1a2d157e67e1ba238bcd07f526a955fc84779477ad9b36b63b72d9ae402c6ce196f7ea4fccc503478a4ee9c77aa4bc22804434620362ab8a2  version.patch
"
